1. Technical Field
The present invention relates generally to an improved data processing system and in particular to a method and apparatus for processing data. Still more particularly, the present invention provides a method, apparatus, and computer instructions for referencing a constant pool.
2. Description of Related Art
Java is an object-oriented programming language designed to generate applications that can run on all different types of data processing systems without modification. Developed by Sun Microsystems, Inc. Java has been promoted and geared heavily for the Web, both for public Web sites and intranets. Java programs can be called from within HTML documents or launched standalone. When a Java program called from a Web page runs on a user's machine, this program is called a “Java applet.” When a Java program is run on a Web server, it is called a “servlet.” A Java program running on a data processing system as a stand-alone non Web-based program is simply referred to as a “Java application.”
Java uses an intermediate language called “bytecode.” Bytecodes are nonspecific to hardware platforms. The source code of a Java program is compiled into bytecode, which can be moved from one hardware platform to another. In order to run the Java program, it must be compiled into machine code first. The compilation is done either ahead of time like a C/C++ program, a line at a time like an interpreter, or as needed using a just-in-time compiler.
In executing a Java program, such as a Java applet, the Web browser invokes a Java virtual machine (JVM). This component translates bytecodes into machine code for execution. As a result, Java programs are not dependent on any specific hardware and will run in any data processing system with a Java virtual machine.
Many Java bytecodes refer to a constant pool. A constant pool is a collection of data that is stored in the class area in the Java virtual machine. The constant pool is an ordered set of constants used by a class or interface, including literals and symbolic references to types, fields, and methods. The constant pool plays a central role in the dynamic linking of Java programs. The data in the constant pool provides information describing how a bytecode is to be executed. For the Java virtual machine to reference the constant pool, the Java virtual machine must maintain a reference to the start of the constant pool.
Additionally, it is often important for the Java virtual machine to know information about the currently executing Java method. This information may be derived from the program counter, but this process can involve a performance penalty. It is desirable to be able to access both the constant pool and the currently executing method in an efficient manner.
One solution to this problem is for the Java virtual machine to maintain a pointer to the constant pool and a pointer to the current method at all times. This solution generates a new problem because two active pointers are maintained. The pointers reduce the number of processor registers available for other uses and increases the amount of state data saved and restored on Java method invocations.
Another solution involves the Java virtual machine maintaining a pointer to the method at all times and deriving a pointer to the constant pool when access to the constant pool is needed. This solution trades a penalty to access the method pointer for a penalty to access the constant pool. Therefore, it would be advantageous to have an improved method, apparatus, and computer instructions for a Java virtual machine to reference a constant pool.